/*
 *  Copyright (C) 2006 Takeharu KATO
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#if !defined(G2IPMSG_SYMCRYPT_H)
#define G2IPMSG_SYMCRYPT_H
#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#if defined(USE_OPENSSL)
#include <openssl/evp.h>
#define SYMCRYPT_MAX_KEY_TYPE 5
#define RC2_CAPS            (IPMSG_RC2_40|IPMSG_RC2_128|IPMSG_RC2_256)
#define BLOWFISH_CAPS       (IPMSG_BLOWFISH_128|IPMSG_BLOWFISH_256)
#define SYM_CAPS            (RC2_CAPS|BLOWFISH_CAPS)
int ipmsg_get_skey_length(unsigned long type,size_t *ret_len);
int blowfish_cbc_encrypt_setup(const char *key,size_t key_len_byte,const char *iv,EVP_CIPHER_CTX **ret);
int blowfish_cbc_decrypt_setup(const char *key,size_t key_len_byte,const char *iv,EVP_CIPHER_CTX **ret);
int rc2_cbc_encrypt_setup(const char *key,size_t key_len_byte,const char *iv,EVP_CIPHER_CTX **ret);
int rc2_cbc_decrypt_setup(const char *key,size_t key_len_byte,const char *iv,EVP_CIPHER_CTX **ret);
int common_cbc_encrypt(EVP_CIPHER_CTX *ctx, const char *data, int inl, int *rb,char **ret_buff);
int common_cbc_decrypt(EVP_CIPHER_CTX *ctx, const char *ct, int inl,char **ret_buff,size_t *outl);
int common_cbc_finalize(EVP_CIPHER_CTX **ctx_p);
int symcrypt_encrypt_message(unsigned long type,const unsigned char *plain,
			 char **key_p, size_t *key_len_p,char **enc_p,
			     size_t *enc_len_p);
int symcrypt_decrypt_message(unsigned long type,const unsigned char *encoded,
			     size_t enc_len, const char *key,char **dec_p,size_t *dec_len_p);
int select_symmetric_key(unsigned long peer_cap,unsigned long *selected_key,int speed);
#else
#define SYM_CAPS            (0)
#endif  /*  USE_OPENSSL  */
#endif  /*  G2IPMSG_SYMCRYPT_H  */
